class Solution {//leetcode129——求根节点到叶节点数字之和
public:
    int dfs(TreeNode* root,int n){
        if(root==nullptr) return 0;
        int num=n*10+root->val;
        
        if(root->left==nullptr&&root->right==nullptr) return num;

        int left=dfs(root->left,num);
        int right=dfs(root->right,num);
        return left+right;
    }
    int sumNumbers(TreeNode* root) {
        return dfs(root,0);
    }
};